home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / host / mxlookup < prev    next >
Text File  |  1996-10-25  |  3KB  |  164 lines

  1. #!/bin/sh -
  2. #
  3. #    @(#)mxlookup            e07@nikhef.nl (Eric Wassenaar) 950108
  4. #
  5. # Author:    E.Wassenaar, Nikhef-H
  6. # Version:    09-OCT-1994
  7. # Revision:    08-JAN-1995, Make sure servers come from NS records
  8. #
  9. # This utility looks up the MX and A records for a given domain name
  10. # at each of the authoritative servers for the zone it belongs to.
  11. # The printout shows whether or not the servers have the same notion.
  12. # Too often mail is bounced with a "No address or MX record" message
  13. # whereas the mail address is perfectly valid. Usually this happens
  14. # when one of the servers turns out to be misconfigured and the data
  15. # was retrieved unfortunately from just that server.
  16. #
  17. # With the -t option you can verify resource records of another type
  18. # at each of the servers. The -v option shows the SOA record and the
  19. # NS records of the zone to which the given domain name belongs.
  20. # The -r option disables nameserver recursion at the contacted servers.
  21.  
  22. exec=echo
  23. exec=
  24.  
  25. # ----------------------------------------------------------------------
  26. # Setup environment.
  27. # ----------------------------------------------------------------------
  28.  
  29. # This is where the ``host'' executable lives.
  30. BINDIR=/usr/local/bin
  31.  
  32. PATH=${BINDIR}:/bin:/usr/bin:/usr/ucb ; export PATH
  33.  
  34. cmd=`basename $0`
  35.  
  36. options="[-v] [-r] [-t type]"
  37. usage="Usage: $cmd $options name"
  38.  
  39. # ----------------------------------------------------------------------
  40. # Exit codes from <sysexits.h>
  41. # ----------------------------------------------------------------------
  42.  
  43. EX_OK=0
  44. EX_USAGE=64
  45. EX_UNAVAILABLE=69
  46.  
  47. # ----------------------------------------------------------------------
  48. # Process options.
  49. # ----------------------------------------------------------------------
  50.  
  51. type=""
  52. recurse=
  53. verbose=
  54.  
  55. skip=
  56. for i
  57. do
  58.     if [ $skip ]
  59.     then
  60.         skip=
  61.         continue
  62.     fi
  63.  
  64.     case "$i" in
  65.     -t)    
  66.         case "$2" in
  67.         ""|-*)    echo "$usage" 1>&2 ; exit $EX_USAGE
  68.         esac
  69.  
  70.         type="$2"
  71.         skip=true
  72.         shift
  73.         ;;
  74.     -r)
  75.         recurse="-r"
  76.         ;;
  77.     -d)
  78.         exec=echo
  79.         ;;
  80.     -v)
  81.         verbose=true
  82.         ;;
  83.     -*)
  84.         echo "$cmd: Unknown option $i" 1>&2 ; exit $EX_USAGE
  85.         ;;
  86.     *)
  87.         break
  88.         ;;
  89.     esac
  90.     shift
  91. done
  92.  
  93. # ----------------------------------------------------------------------
  94. # Process arguments.
  95. # ----------------------------------------------------------------------
  96.  
  97. name="$1"
  98.  
  99. if [ "X$name" = "X" ]
  100. then
  101.     echo "$usage" 1>&2 ; exit $EX_USAGE
  102. fi
  103.  
  104. # Remove trailing dots.
  105. name=`echo $name | sed 's/\.*$//'`
  106.  
  107. # ----------------------------------------------------------------------
  108. # Main loop.
  109. # ----------------------------------------------------------------------
  110.  
  111. domain="$name"
  112.  
  113. while [ "X$domain" != "X" ]
  114. do
  115.     # Make sure there is at least one dot.
  116.     parentdomain=`echo $domain | sed 's/^[^.]*\.//'`
  117.  
  118.     if [ "X$parentdomain" = "X$domain" ]
  119.     then
  120.         domain=""
  121.         continue
  122.     fi
  123.  
  124.     # Find the servers for this domain.
  125.     servers=`host -t NS "$domain" | awk '$2 == "NS" {print $3}'`
  126.  
  127.     if [ "X$servers" = "X" ]
  128.     then
  129.         # Move to parent domain and retry.
  130.         domain="$parentdomain"
  131.         continue
  132.     fi
  133.  
  134.     if [ "X$domain" != "X$name" ]
  135.     then
  136.         echo
  137.     fi
  138.  
  139.     if [ $verbose ]
  140.     then
  141.         echo "--- $domain ---"
  142.         $exec host -T -t SOA "$domain"
  143.         $exec host -T -t NS  "$domain"
  144.         echo
  145.     fi
  146.  
  147.     for server in $servers
  148.     do
  149.         echo "--- $server ---"
  150.         if [ "X$type" = "X" ]
  151.         then
  152.             $exec host $recurse -T -t MX "$name" "$server"
  153.             $exec host $recurse -T -t A  "$name" "$server"
  154.         else
  155.             $exec host $recurse -T -t "$type" "$name" "$server"
  156.         fi
  157.         echo
  158.     done
  159.  
  160.     exit $EX_OK
  161. done
  162.  
  163. exit $EX_UNAVAILABLE
  164.